#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "core_cm3.h"
// #include "printf.h"
void NVIC_Init()
{
   //16级抢占
	__NVIC_SetPriorityGrouping(4);

	/*systick 配置*/
	SysTick_Config(SystemCoreClock/1000);

	/*NVIC*/
	__NVIC_SetPriority(SVCall_IRQn, 15);
	__NVIC_SetPriority(PendSV_IRQn, 15);
	__NVIC_SetPriority(SysTick_IRQn, 15);

	__NVIC_GetEnableIRQ(SVCall_IRQn);
	__NVIC_GetEnableIRQ(PendSV_IRQn);
	__NVIC_GetEnableIRQ(SysTick_IRQn);


}

void task0(void *arg)
{
	(void)arg;
	while (1)
	{
		// printf("task0 run.\r\n");
		vTaskDelay(1000);
	}
}

void task1(void *arg)
{
	(void)arg;
	while (1)
	{
		// printf("task1 run.\r\n");
		LED_ON();
		vTaskDelay(500);
		LED_OFF();
		vTaskDelay(500);
	}
}

void freertos_init()
{
	NVIC_Init();
	TaskHandle_t Task0_handle, Task1_handle;

//	xTaskCreate(task0, "task0", 1024, NULL, 1, &Task0_handle);
	xTaskCreate(task1, "task1", 1024, NULL, 2, &Task1_handle);
	// printf("vTaskStartScheduler\r\n");
	vTaskStartScheduler();
	while (1)
	{
	}
}
